#ifndef G3_SINGLETON_H
#define G3_SINGLETON_H

#include "log.h"

namespace G3 {

template <class SType>
class SINGLETON {
	private:
		static SType *pSingleton;
	
	public:
		SINGLETON () {
			Assert (!pSingleton, "SINGLETON::SINGLETON: Multiple instantiation");
			pSingleton = static_cast <SType*> (this);
		}
		
		virtual ~SINGLETON () {
			Assert (pSingleton, "SINGLETON::~SINGLETON: Singleton not instantiated");
			pSingleton = NULL;
		}
		
		static SType& GetSingleton () {
			Assert (pSingleton, "SINGLETON::~SINGLETON: Singleton not instantiated");
			return (*pSingleton);
		}
		
		static SType* GetSingletonPtr () {
			return pSingleton;
		}
};

template <class SType>
SType* SINGLETON <SType>::pSingleton = NULL;

}

#endif
